<html>
<head><meta charset="utf-8"><title>Compling rustc crate under a profiler · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html">Compling rustc crate under a profiler</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="214124187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/214124187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#214124187">(Oct 21 2020 at 22:42)</a>:</h4>
<p>I'm trying to compile rustc_middle with rustc running under a profiler, and I'm not sure of the best way of doing that.</p>
<p>To enable profiling, I added <code>llvm.release-debuginfo = true</code> and <code>rust.debuginfo-level = 1</code> to config.toml and built a stage1 rustc. I copied <code>build/.../stage1/</code> to a separate location and created a toolchain for it using rustup. I'm not sure if it matters much that I'm using a stage1 instead of a stage2, btw.</p>
<p>Now I want compile rustc_middle using this rustc running under a profiler. To profile, I think I need to run rustc directly rather through cargo. So I'd like to know how rustc gets invoked when compiling this crate. I considered two ways of doing that.</p>
<ol>
<li>
<p><code>cd compiler/rustc_middle &amp;&amp; cargo +abc build -vv &amp;&gt; build.log</code>.</p>
</li>
<li>
<p>Set <code>build.rustc</code> (what to use for bootstrap compiler) in config.toml to my previously built stage1 rustc and do a <code>./x.py build -vv --stage 0 compiler/rustc &amp;&gt; build.log</code>.</p>
</li>
</ol>
<p>And either way, get the rustc command that builds rustc_middle from the log.</p>
<p>First, is one of these ways more sensible than the other? Is there a better way?</p>
<p>Second, method 2 gives me an error: </p>
<div class="codehilite"><pre><span></span><code>$ ./x.py build -i -j5 --stage 0 compiler/rustc
Updating only changed submodules
Submodules updated in 0.02 seconds
   Compiling toml v0.5.7
error[E0460]: found possibly newer version of crate `std` which `serde` depends on
 --&gt; /home/tgnottingham/.cargo/registry/src/github.com-1ecc6299db9ec823/toml-0.5.7/src/macros.rs:1:9
  |
1 | pub use serde::de::{Deserialize, IntoDeserializer};
  |         ^^^^^
  |
  = note: perhaps that crate needs to be recompiled?
  = note: the following crate versions were found:
          crate `std`: /home/tgnottingham/Projects/rust/toolchains/abc/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-a0f0aab31a0efbe4.rlib
          crate `std`: /home/tgnottingham/Projects/rust/toolchains/abc/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-a0f0aab31a0efbe4.so
          crate `serde`: /home/tgnottingham/Projects/rust/rust/build/bootstrap/debug/deps/libserde-294f8c7e9ce0a347.rmeta

error: aborting due to previous error

error: could not compile `toml`
</code></pre></div>


<p>If method 2 is the avenue I should be pursuing, how can I resolve the above error?</p>



<a name="214124574"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/214124574" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#214124574">(Oct 21 2020 at 22:48)</a>:</h4>
<p>I would not recommend trying to build without rustc or x.py, you need <code>--sysroot</code> and <code>RUSTC_REAL</code> and all sorts of other stuff</p>



<a name="214124620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/214124620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#214124620">(Oct 21 2020 at 22:48)</a>:</h4>
<p>if you can get method 1 to work that seems reasonable</p>



<a name="214124761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/214124761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#214124761">(Oct 21 2020 at 22:50)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Compling.20rustc.20crate.20under.20a.20profiler/near/214124574">said</a>:</p>
<blockquote>
<p>I would not recommend trying to build without rustc or x.py, you need <code>--sysroot</code> and <code>RUSTC_REAL</code> and all sorts of other stuff</p>
</blockquote>
<p>Do you mean without cargo or x.py?</p>



<a name="214124829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/214124829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#214124829">(Oct 21 2020 at 22:50)</a>:</h4>
<p>yes <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span> thank you</p>



<a name="214124855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/214124855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#214124855">(Oct 21 2020 at 22:51)</a>:</h4>
<p>Cool, thank you! I'll give it a try.</p>



<a name="214124893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/214124893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#214124893">(Oct 21 2020 at 22:51)</a>:</h4>
<p>the other alternative is setting <code>RUSTFLAGS</code> or <code>CARGOFLAGS</code></p>



<a name="214130269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/214130269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#214130269">(Oct 22 2020 at 00:09)</a>:</h4>
<p>For anyone who is trying to accomplish something like this, I was able to get valgrind-based profiling working via method 1. You can take the rustc command that builds the crate of interest from the verbose output of <code>cargo +&lt;your-toolchain&gt; build -vv</code> and modify it a bit.</p>
<p>It will look something like:</p>
<div class="codehilite"><pre><span></span><code>CARGO=... CARGO_CRATE_NAME=&lt;crate_of_interest&gt; ...more cargo env vars... LD_LIBRARY_PATH=... rustc ...many arguments...
</code></pre></div>


<p>To run compilation under cachegrind, for example, replace the <code>rustc</code> above with:</p>
<div class="codehilite"><pre><span></span><code>valgrind --tool=cachegrind $(rustup +&lt;your-toolchain&gt; which rustc)
</code></pre></div>


<p>Not sure this is the "right" way, but it's something. Only trouble is that massif is segfaulting on me, but I think that's a massif issue.</p>



<a name="214133314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/214133314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#214133314">(Oct 22 2020 at 01:00)</a>:</h4>
<p>I was able to get past the massif segfault by upgrading from valgrind 3.15 to 3.16.1.</p>
<p>But the method of running cargo in the crate directory doesn't work for all crates apparently. Some crates want env vars like <code>CFG_RELEASE_CHANNEL</code> to be defined, and they aren't. I could probably work around that, but it makes me think I should be doing this a different way.</p>



<a name="214133340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/214133340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#214133340">(Oct 22 2020 at 01:01)</a>:</h4>
<p><span class="user-mention" data-user-id="306073">@Tyson Nottingham</span> <code>export CFG_RELEASE_CHANNEL=nightly</code></p>



<a name="214133364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/214133364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#214133364">(Oct 22 2020 at 01:01)</a>:</h4>
<p>(or maybe rustc-dev? not 100% sure)</p>



<a name="214134028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/214134028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#214134028">(Oct 22 2020 at 01:13)</a>:</h4>
<p>Setting that and <code>CFG_RELEASE=blah</code> gets me past it. Thanks <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="214146148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/214146148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#214146148">(Oct 22 2020 at 05:53)</a>:</h4>
<p><span class="user-mention" data-user-id="306073">@Tyson Nottingham</span> Cheering you on here. I'm so glad you're working on this.</p>



<a name="214278568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/214278568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#214278568">(Oct 23 2020 at 06:36)</a>:</h4>
<p>Thanks <span class="user-mention" data-user-id="239881">@Josh Triplett</span>, the cheering helps <span aria-label="smiley" class="emoji emoji-1f603" role="img" title="smiley">:smiley:</span></p>



<a name="218613566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/218613566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#218613566">(Dec 02 2020 at 20:21)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> Making some progress -- <a href="https://github.com/rust-lang/rust/pull/79589">https://github.com/rust-lang/rust/pull/79589</a>. Only improves things for incremental builds, but that's where the lowest fruit lies.</p>



<a name="218614012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/218614012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#218614012">(Dec 02 2020 at 20:23)</a>:</h4>
<p>Very nice work! Impressive improvement.</p>



<a name="218614162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compling%20rustc%20crate%20under%20a%20profiler/near/218614162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compling.20rustc.20crate.20under.20a.20profiler.html#218614162">(Dec 02 2020 at 20:24)</a>:</h4>
<p><span aria-label="blush" class="emoji emoji-1f60a" role="img" title="blush">:blush:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>